import {Switch,Route,Redirect} from "react-router-dom"
const routerView =(props)=>{
    if(!props.routes){
        return null;
    }
    const routes=props.routes.filter(item=>item.component);
    const redirects=props.routes.filter(item=>!item.component);
    return (<Switch>
       {routes.map((item,index)=>{
           return <Route path={item.path} key={index} render={routerProps=>{
               return <item.component {...routerProps} routes={item.children||[]}/>
           }}/>
       })}
       {redirects.map((item,index)=>{
           return <Redirect from={item.from} to={item.to} key={index}/>
       })}
    </Switch>)
}
export default routerView;